package com.bnz.controller;

import com.bnz.exception.TestException;
import com.bnz.pojo.R;
import com.bnz.pojo.Student;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
public class FirstController {

    @RequestMapping("/first")
    public R first(String name){
        if ("张三".equals(name)){
            throw new TestException("名字不能是张三");
        }
        System.out.println("调用了hello()方法！");
        return R.ok();
    }

    @GetMapping("/list")
    public R list(){
        List<Student> studentList = new ArrayList<>();
        studentList.add(new Student(1001,"张三","男",21,"深圳",1));
        studentList.add(new Student(1002,"秦始皇","男",2000,"西安",2));
        studentList.add(new Student(1003,"慈禧太后","女",372,"北京",3));
        return R.ok().put("students",studentList);
    }
}
